/**
 ********************************************************************
 * @author roocket
 * @file    file_crypt.h
 * @version V0.0.0
 * @date    2024/3/22
 * @brief   This file is to indicate file cryptogram functions. 
 * @attention Code file rules:
 * rule: file encoding use UTF8;
 * rule: max line length 120 characters;
 * rule: line separator \r\n;
 * rule: use clion auto code format tool.
 */

#ifndef _FILE_CRYPT_H_
#define _FILE_CRYPT_H_

#include <stdio.h>
#include <string.h>
#include <openssl/evp.h>

#define FILE_NUMBER 100
#define FILE_1K 1024
#define FILE_1M (FILE_1K) * (FILE_1K)
#define FILE_NK (FILE_1K) * (FILE_NUMBER)
#define FILE_CRYPTOGRAM_BUFFER_LEN (FILE_NK)

#define FILE_SALT "000000"

/**
 * @brief Encrypte data.
 * @note handler for encrypting data based on two 'different' data.
 * @param be_enc_data The data to be encrypted.
 * @param be_enc_len The length for being encrypted.
 * @param enc_dataa The data has been encrypted.[Please free after out-of-use]
 * @param encLen The lenght of encrypted.
 * @param passwd The passwd of encryption.
 * @return Executed result.
 */
int file_crypt_encryt_data(const unsigned char *be_enc_data, const int be_enc_len, unsigned char **enc_dataa, int *encLen, const char *passwd);

/**
 * @brief Encrypte file.
 * @note handler for encrypting file based on two 'different' filenames.
 * @param be_enc_file The file to be encrypted.
 * @param enc_file The file has been encrypted.
 * @param passwd The passwd of encryption.
 * @param t The time of encryption.
 * @return Executed result.
 */
int file_crypt_encryt_file(const char *be_enc_file, const char *enc_file, const char *passwd, double *t);

 /**
 * @brief Decrypte data.
 * @note handler for decrypting data based on two 'different' data.
 * @param be_dec_data The data to be decrypted.
 * @param be_dec_len The length of decrypted data.
 * @param dec_data The data has been decrypted.[Please free after out-of-use]
 * @param dec_len The legnth of decrypted data.
 * @param passwd The passwd of encryption.
 * @return Executed result.
 */
int file_crypt_decrypt_data(const unsigned char *be_dec_data, const int be_dec_len, unsigned char **dec_data, int *dec_len, const char *passwd);

 /**
 * @brief Decrypte file.
 * @note handler for decrypting file based on two 'different' filenames.
 * @param be_dec_file The file to be decrypted.
 * @param dec_file The file has been decrypted.
 * @param passwd The passwd of encryption.
 * @param t The time of decryption.
 * @return Executed result.
 */
int file_crypt_decrypt_file(const char *be_dec_file,  const char *dec_file, const char *passwd, double *t);

#endif /* _FILE_CRYPT_H_ */
